package com.zzyl.nursing.job;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzyl.nursing.domain.DeviceData;
import com.zzyl.nursing.mapper.DeviceDataMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

@Component
@Slf4j
public class NewScheduledTask {

    @Autowired
    private DeviceDataMapper deviceDataMapper;

    @Scheduled(cron = "0 50 20 * * ?")
    public void executeTask(){
        log.info("删除大于15天的数据");

        LocalDateTime cutoffTime = LocalDateTime.now().minusDays(15);
        log.info("删除 {} 之前的数据", cutoffTime);

        deviceDataMapper.delete(new LambdaQueryWrapper<DeviceData>().le(DeviceData::getAlarmTime,cutoffTime));

    }

}
